package cn.tedu.sp04.Controller;

import cn.tedu.sp1.Service.OrderService;
import cn.tedu.sp1.Web.Util.JsonResult;
import cn.tedu.sp1.entity.Item;
import cn.tedu.sp1.entity.Order;
import cn.tedu.sp1.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Arrays;

@RestController
public class OrderController {
    @Autowired
    private OrderService orderService ;

    @GetMapping("{orderId}")
    public JsonResult<Order> getorder(String OrderId){
        Order order = orderService.getOrder(OrderId);
        return JsonResult.ok().data(order);
    }
    @GetMapping("/add")
    public JsonResult<?> addorder(){
        Order order = new Order();
        order.setId("11");
        order.setUser(new User(8,null,11111));
        order.setItems(Arrays.asList(new Item[]{
                new Item(1,"a",1),
                new Item(2,"a",2),
                new Item(2,"a",2)
        }));

        orderService.addOrder(order);
        return JsonResult.ok().msg("添加完成");
    }
    @GetMapping("favicon.ico")
    public void  ico(){

    }
}
